package com.woniuxy.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.RoleDao;
import com.woniuxy.entity.Role;
import com.woniuxy.entity.RoleDto;
import com.woniuxy.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: TODO(用一句话描述这个类的作用)
 * @Author 18452
 * @Date 2021/4/26 13:11
 */
@Service
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleDao roleDao;

    @Override
    public PageInfo<Role> select(RoleDto roleDto) {

        PageHelper.startPage(roleDto.getPage(),roleDto.getLimit());
        List<Role> roleList = roleDao.select(roleDto.getEditForm());
        PageInfo<Role> pageInfo = new PageInfo<>(roleList);
        return pageInfo;
    }

    @Override
    public List<Role> selectAll() {
        System.out.println(roleDao);
        return roleDao.selectAll();
    }


    @Override
    public String insert(Role role) {
        int row = roleDao.insert(role);
        if(row == 0){
            return "defeated";
        }
        return "success";
    }

    @Override
    public String update(Role role) {
        int row = roleDao.update(role);
        if(row == 0){
            return "defeated";
        }
        return "success";
    }

    @Override
    public String delete(int id) {
        int row = roleDao.delete(id);
        if(row == 0){
            return "defeated";
        }
        return "success";
    }

}
